from odoo.http import request
from odoo import http
import json


class MesMain(http.Controller):

    @http.route("/v1.0/mes/basicData", auth='public', type='json', methods=['POST', "POST"], csrf=False, cors='*')
    def mes_basic(self, **kwargs):
        types = kwargs.get('type')
        ids = kwargs.get('ids')
        if types == 'product':  # 产品上传
            request.env['product.template'].sudo().search([('id', 'in', ids)]).template_mes_upload()
        if types == 'category':  # 部门上传
            request.env['product.category'].sudo().search([('id', 'in', ids)]).categ_upload_mes()
        if types == 'workcenter':  # 工序
            request.env['mrp.workcenter'].sudo().search([('id', 'in', ids)]).workcenter_upload_mes()
        if types == 'station':  # 工站
            request.env['work.station'].sudo().search([('id', 'in', ids)]).station_upload_mes()
        if types in ['customer', 'supplier']:  # 客户供应商
            domain = [('id', 'in', ids), ('is_company', '=', True)]
            pp = request.env['res.partner'].sudo().with_context({'type': types}).search(domain)
            pp.partner_upload_mes()
        if types == 'warehouse':  # 仓库
            request.env['stock.warehouse'].sudo().search([('id', 'in', ids)]).warehouse_upload_mes()
        if types == 'location':  # 位置
            request.env['stock.location'].sudo().search([('id', 'in', ids)]).location_upload_mes()
        if types == 'job':  # 岗位
            request.env['hr.job'].sudo().search([]).job_upload_mes()
        if types == 'employee':  # 员工
            request.env['hr.employee'].sudo().search([('id', 'in', ids)]).employee_upload_mes()

        return {"code": 200, "data": {"version": "1.0.0", "name": "mes"}}
